package com.ziyun.erp.web.modules.remittance.controller;

import com.ziyun.erp.modules.remittance.entity.BankInfoEntity;
import com.ziyun.erp.modules.remittance.entity.RemittanceEntity;
import com.ziyun.erp.modules.remittance.service.RemittanceService;
import com.ziyun.erp.modules.supp.entity.SellerInfoEntity;
import com.ziyun.erp.modules.supp.service.SellerInfoService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 供应商打款信息表
 *
 * @author jiangli
 * @email
 * @date 2018-11-13 08:34:23
 */
@RestController
@RequestMapping("remittance/remittance")
public class RemittanceController {
    @Autowired
    private RemittanceService remittanceService;
    @Autowired
    private SellerInfoService sellerInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("remittance:remittance:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = remittanceService.list(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("remittance:remittance:info")
    public R info(@PathVariable("id") Integer id) {
        RemittanceEntity remittance = remittanceService.selectById(id);
        SellerInfoEntity sellerInfoEntity = sellerInfoService.selectById(remittance.getSellerId());
        remittance.setSellerName(sellerInfoEntity.getSellerName());
        return R.ok().put("remittance", remittance);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("remittance:remittance:save")
    public R save(@RequestBody RemittanceEntity remittance) {
        return remittanceService.insertEntity(remittance);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("remittance:remittance:update")
    public R update(@RequestBody RemittanceEntity remittance) {
        ValidatorUtils.validateEntity(remittance);
        remittanceService.updateById(remittance);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("remittance:remittance:delete")
    public R delete(@RequestBody Integer[] ids) {
        remittanceService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

    //所属门店集合
    @RequestMapping("/getsellerNames")
    public List<Map<String, Object>> getsellerNames() {
        return remittanceService.getsellerNames();
    }

    //銀行信息集合
    @RequestMapping("/bankInfos")
    public List<BankInfoEntity> bankInfos() {
        return remittanceService.bankInfos();
    }

}
